﻿using Ekton_Manage_DomainCore.Aggregate;
using Ekton_Manage_DTO.APIRequestModels.SysUser;
using Ekton_Manage_DTO.RequestModels;
using Ekton_Manage_IBusiness;
using Ekton_Manage_InfrastructureCore.Common;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace Ekton_Manage_Web.Controllers
{
    /// <summary>
    /// 前端订单
    /// </summary>
    /// 
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize("Permission")]
    public class ApiOrderController : ControllerBase
    {
    
        private readonly IApiSelectOrder _apiSelectOrder;
        public ApiOrderController(IApiSelectOrder apiSelectOrder)
        {          
            _apiSelectOrder = apiSelectOrder;
        }

        /// <summary>
        /// 查询订单
        /// </summary>
        /// 
        [HttpGet]
        public async Task<MessageModel<PageModel<user_orderView>>> ApiGetOrderList([FromQuery] QueryDataParame query)
        {
            var result = await _apiSelectOrder.GetOrder(query);

            return new MessageModel<PageModel<user_orderView>>
            {
                msg = "数据获取成功",
                response = new PageModel<user_orderView>
                {
                    pageIndex = query.pageIndex,
                    pageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(result.Item2) / query.pageSize)),
                    dataCount = result.Item2,
                    pageSize = query.pageSize,
                    data = result.Item1
                }
            };
        }

        /// <summary>
        /// 提交需求订单  
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Message> ApiPostOrderList([FromBody] ApiDtoInsertUserOrder request)
        {
            return await _apiSelectOrder.PostOrderList(request);
        }


        /// <summary>
        /// 查看详情
        /// </summary>
        /// <param name="order_id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Message> GetParticularsOrder(string order_id)
        {
            var result = await _apiSelectOrder.GetParticularsOrder(order_id);
     
            return result;
        }



        /// <summary>
        /// 修改备注
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        /// 
        [HttpPut]
        public async Task<Message> PutRemark(ApiDtoUpdateRemark request)
        {
            return await _apiSelectOrder.PutRemark(request);
       
        }
    }
}
